<?php

namespace Portal\Common;

class Jwt
{
    /**
     * @param $dataArr
     * @return mixed
     */
    public static function generateToken($payload)
    {
        if (!isset($payload['id']) || !isset($payload['exp']) || !isset($payload['role']) || !isset($payload['username'])) {
            throw new \PhalApi\Exception\BadRequestException("plaload[id]与payload['exp']不能为空plaload[role]与payload['username']不能为空");
        }
        $token = \PhalApi\DI()->jwt->encodeJwt($payload);
        \PhalApi\DI()->logger->debug('token:'.$token);
        return $token;
    }

    /**
     * 获取管理员ID
     * @return mixed
     */
    public static function getAdminId()
    {
        $payload = \PhalApi\DI()->jwt->decodeJwt();
        return $payload['id'];
    }
}
